#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int dis[N];
void dfs(int u, int fu, int d) {
  dis[u] = d;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    int w = W[i];
    if (v == fu) continue;
    dfs(v, u, dis[u] ^ w);
  }
}
int tr[N * 32][10], num;
void insert(int x) {
  int p = 0;
  per(i, 30, 0) {
    int ch = (x & (1 << i)) ? 1 : 0;
    if (!tr[p][ch]) tr[p][ch] = ++num;
    p = tr[p][ch];
  }
}
int search(int x) {
  int res = 0;
  int p = 0;
  per(i, 30, 0) {
    int ch = (x & (1 << i)) ? 1 : 0;
    if (!tr[p][ch]) ch ^= 1;
    p = tr[p][ch];
    if (ch) res |= 1 << i;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  dfs(1, 1, 0);
  rep(i, 1, n) insert(dis[i]);
  int ans = 0;
  rep(i, 1, n) {
    int x = search(~dis[i]);
    ans = max(ans, x ^ dis[i]);
  }
  cout << ans;
  return 0;
}